package com.leizhou.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author LT
 * @version 1.0.0
 * @ClassName LoginInterceptor.java
 * @Description TODO 自定义拦截器
 * @createTime 2020年04月16日 17:02:00
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    /** 前置拦截  一般用于登录*/
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        log.debug("=========preHandle==========");
        // response.sendRedirect("http://www.jd.com");
        // 返回true: 不拦截 false: 拦截
        return true;
    }

    /** 后置拦截 */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {
        log.debug("=========postHandle==========");
    }

    /** 视图渲染完成后拦截 */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
                                Object handler, Exception ex) throws Exception {
        log.debug("=========afterCompletion==========");
    }
}
